<#
.SYNOPSIS
Zip up files and folders
.EXAMPLE
To zip up some files:
    ls c:\source\*.txt | out-zip.ps1 c:\target\archive.zip
.EXAMPLE
To zip up a folder:
    gi c:\source | out-zip c:\target\archive.zip
#>

param(
    [parameter(Mandatory=$TRUE,ValueFromPipeline=$TRUE)] $files,
    [parameter(Mandatory=$TRUE,position=0)] [string] $path
)

if (-not $path.EndsWith('.zip')) {$path += '.zip'} 

if (-not (test-path $path)) { 
  set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) 
} 

$zipFile = (new-object -com shell.application).NameSpace([System.IO.Path]::GetFullPath($path)) 
foreach($file in $files) 
{ 
    $zipfile.CopyHere($file.FullName)    
    $size = $zipfile.Items().Item($file.Name).Size
    while($zipfile.Items().Item($file.Name) -Eq $null)
    {
        start-sleep -milliseconds 500
    }
}
